package cn.lg.soar.system.biz.modules.auth.controller;

import cn.lg.soar.common.enums.LogTypeEnum;
import cn.lg.soar.common.model.HttpResult;
import cn.lg.soar.common.model.PageQuery;
import cn.lg.soar.common.model.PageResult;
import cn.lg.soar.core.annotations.IdempotentByParam;
import cn.lg.soar.core.annotations.constraints.group.Create;
import cn.lg.soar.core.annotations.constraints.group.Update;
import cn.lg.soar.database.base.controller.BaseController;
import cn.lg.soar.database.query.QueryParams;
import cn.lg.soar.mvc.annotations.DisabledTenantAccess;
import cn.lg.soar.mvc.annotations.Log;
import cn.lg.soar.system.api.constant.ModuleConst;
import cn.lg.soar.system.biz.modules.auth.entity.PostTag;
import cn.lg.soar.system.biz.modules.auth.service.PostTagService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

/**
 * 职位标签
 * @author luguoxiang
 * @since 2025-08-14
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
@Tag(name = "职位标签")
@Validated
@RestController
@RequestMapping(ModuleConst.MODULE_NAME + "/post-tag")
public class PostTagController extends BaseController<PostTag, PostTagService> {

    @Override
    protected Serializable getId(PostTag entity) {
        return entity.getId();
    }

    @DisabledTenantAccess
    @Log(value = "新增职位标签", type = LogTypeEnum.CREATE)
    @IdempotentByParam("#p0")
    @Operation(summary = "新增")
    @RequestMapping(path = "create", method = RequestMethod.POST)
    public HttpResult<Serializable> create(@RequestBody @Validated(Create.class) PostTag data) {
        return super.createResult(data);
    }

    @DisabledTenantAccess
    @Log(value = "修改职位标签", type = LogTypeEnum.UPDATE)
    @Operation(summary = "修改")
    @RequestMapping(path = "update", method = RequestMethod.POST)
    public HttpResult<Void> update(@RequestBody @Validated(Update.class) PostTag data) {
        return super.updateResult(data);
    }

    @DisabledTenantAccess
    @Log(value = "删除职位标签", type = LogTypeEnum.REMOVE)
    @Operation(summary = "删除", description = "根据 id 删除")
    @RequestMapping(path = "remove", method = RequestMethod.POST)
    public HttpResult<Void> remove(@RequestBody List<Long> ids) {
        return super.removeResult(ids);
    }

    @Operation(summary = "详情", description = "根据 ID 获取一条数据")
    @RequestMapping(path = "detail", method = RequestMethod.GET)
    public HttpResult<PostTag> detail(@RequestParam(name = "id") Long id) {
        return super.detailResult(id);
    }

    @Operation(summary = "查询", description = "多功能查询（分页、列表、统计）")
    @RequestMapping(path = "query", method = RequestMethod.GET)
    public HttpResult<PageResult<PostTag>> query(PageQuery pageQuery, QueryParams params){
        return super.queryResult(pageQuery, params);
    }

    @Log(value = "导出职位标签", type = LogTypeEnum.EXPORT)
    @Operation(summary = "导出")
    @RequestMapping(path = "export", method = RequestMethod.GET)
    public void exports(@RequestParam(name = "filename", required = false) String filename, QueryParams params, HttpServletResponse resp){
        super.exportExcel(filename, params, resp);
    }

    @DisabledTenantAccess
    @Log(value = "导入职位标签", type = LogTypeEnum.IMPORT)
    @Operation(summary = "导入")
    @RequestMapping(path = "import", method = RequestMethod.POST)
    public HttpResult<Void> imports(HttpServletRequest req){
        return super.importExcel(req);
    }

}